import { ref } from 'vue'
import { adapter, withIgnoreValid } from '@/request'

interface BaxResponse {
  result: {
    mobile: string
    success: boolean
    token: string
    uid: string
  }
}

export default function shopLogin() {
  const service = adapter<BaxResponse>(withIgnoreValid)
  const loading = ref(false)

  const fetch = (url: string, params: { mobile: number; hash: string }) => {
    loading.value = true

    return service({
      config: {
        url,
        method: 'get',
        params
      },
      error: (err) => {
        console.log(err)
      },
      done: () => {
        loading.value = false
      }
    })
  }

  return [null, fetch, loading] as const
}
